<?php
require_once('../model/class.cates.php');
$qiCate = new qiCate($DB);

if($ts == 'list')
{
$pageurl = '';
$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$pageurl .= './index.php?action=cate&ts=list&page';

$cates = $qiCate->getCate($page,8);

$virtue = "id";
$setvirtue = "id";
$catenum = $qiCate->getCateNum($virtue, $setvirtue);

$page_url = pagination($catenum, 8, $page, $pageurl);
}

if($ts == 'add')
{
$userid = isset($uid) ? $uid : '';
$cname = isset($_POST['cname']) ? $_POST['cname'] : '';
$ctime = time();
if(!empty($cname))
{
$qiCate->addCate($userid,$cname,$ctime,0);
header("Location: index.php?action=cate&ts=list");
}
}

if($ts == 'edit')
{
$cid = isset($_GET['id']) ? $_GET['id'] : '';
$cateDate = $qiCate->getOneCate($cid);
}

if($ts == 'update')
{
$cname = isset($_POST['cname']) ? $_POST['cname'] : '';
$cset = isset($_POST['cset']) ? $_POST['cset'] : '';
$uid = isset($_GET['id']) ? $_GET['id'] : '';
$cateDate = array(
'cname' => $cname,
'cset' => $cset
);
$qiCate->updateCates($cateDate,$uid);
header("Location: index.php?action=cate&ts=list");

}

if($ts == 'del')
{
$cid = isset($_GET['id']) ? $_GET['id'] : '';
$qiCate->deleteCate($cid);
header("Location: index.php?action=cate&ts=list");
}

if($ts == 'set')
{

}

?>
